package demo

import (
	"context"
	"userver/protos/pbdemo"

	"gitee.com/cloudapex/ulern/rpc"
	"gitee.com/cloudapex/ulern/util"
	"google.golang.org/grpc"
)

func init() {
	rpc.RegistServer(func(s *grpc.Server) { pbdemo.RegisterDemoServer(s, (&Server{}).Init("demo")) })
}

type Server struct {
	util.LogMe

	pbdemo.UnimplementedDemoServer
}

func (this *Server) Init(name string) *Server {
	this.LogMe.Init("GRPC", func() string { return name })
	return this
}

/*
 * 描述: 示例
 * 方法: Simple
 *********************************************************************/
func (this *Server) Hello(ctx context.Context, req *pbdemo.HelloReq) (*pbdemo.HelloRsp, error) {

	rsp := pbdemo.HelloRsp{}
	if err := util.Convert(req, &rsp); err != nil {
		return nil, rpc.RespConvertErr("", err)
	}
	return &rsp, nil
}
